

<include file="public@header" />
</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li class="active"><a >用户信息</a></li>
    </ul>

    <form class="well form-inline margin-top-20" method="get" >

        用户ID:
        <input type="text" class="form-control" id="user_login" style="width: 120px;"  placeholder="请输入用户ID">

        电话:
        <input type="text" class="form-control" id="mobile" style="width: 120px;"  placeholder="请输入电话">


        积分:
        <input type="text" class="form-control" id="scorea" style="width: 120px;"  placeholder="请输入积分">~
        <input type="text" class="form-control" id="scoreb" style="width: 120px;"  placeholder="请输入积分">


        <input type="button" id="selectval" class="btn btn-primary" value="搜索" />
        <a class="btn btn-danger" href="{:url('index')}">清空</a>
    </form>

    <table class="table table-hover table-bordered">

        <table class="layui-hide" id="test" lay-filter="test"></table>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-sm" id="allscore" >总积分</button>
            </div>
        </script>
        <script type="text/html" id="barDemo">

            <a class="layui-btn layui-btn-xs" lay-event="congzi">充值</a>
            <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="kouchu">扣除</a>
            <a class="layui-btn layui-btn-xs" lay-event="zengsong">赠送</a>
            <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="baoming">报名</a>
            <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>

        </script>

        <!--    自定义    -->
        <script type="text/html" id="titleTpl">
            <a class="layui-btn layui-btn-xs layui-btn-primary layui-border-green" lay-event="shiming">{{d.shiming}}</a>
        </script>

        <script type="text/html" id="titleTpl1">
            <a class="" lay-event="scorelog"> {{d.score }}</a>
        </script>
        <script type="text/html" id="titleTpl2">
            <a class="" lay-event="game">比赛 </a>
        </script>
        <script type="text/html" id="titleTpl3">
            <a class="" lay-event="ticket">兑换券 </a>
        </script>
        <script type="text/html" id="titleTpl4">
            {{#  if(!d.car_name){ }}
            未实名
            {{#  } else { }}
            {{d.car_name}}
            {{#  } }}
        </script>



        <script>

            layui.use('table', function(){
                var table = layui.table;
                var tableIns =table.render({
                    elem: '#test' ,
                    url:'index',
                    method: 'post',
                    toolbar: '#toolbarDemo',
                    title: '用户数据表',
                    totalRow: true ,
                    cols: [[
                        {field:'id', title:'ID', width:80, fixed: 'left',  totalRowText: '合计'}
                        // ,{field:'car_name', title:'实名', templet: '#titleTpl4'}
                        ,{field:'user_nickname', title:'用户名',edit: 'text'}
                        ,{field:'mobile', title:'电话'}
                        ,{field:'shiming', title:'实名', templet: '#titleTpl'}
                        ,{field:'score', title:'积分', sort: true, totalRow: true, templet: '#titleTpl1'}
                        ,{field:'shiming', title:'比赛', templet: '#titleTpl2'}
                        ,{field:'shiming', title:'兑换券', templet: '#titleTpl3'}
                        ,{field:'create_time', title:'加入时间'}
                        ,{fixed: 'right', title:'操作',width:300, toolbar: '#barDemo'}
                    ]]
                    ,page: true,
                    done: function(res, curr, count){
                        console.log(res);
                        $("#allscore").html('合计积分:'+res.msg)
                    }
                });

                $("#selectval").click(function (){
                    var name=$("#user_login").val();
                    var mobile=$("#mobile").val();


                    var scorea=$("#scorea").val();
                    var scoreb=$("#scoreb").val();
                    tableIns.reload({
                        where: { name: name,scorea:scorea,scoreb:scoreb,mobile:mobile } ,
                        page: { curr: 1  }
                    });

                })

                //表格工具行事件
                table.on('tool(test)', function(obj){
                    var data = obj.data;

                    //console.log(obj)
                    if(obj.event === 'del'){
                        layer.confirm('真的删除行么', function(index){
                            $.ajax({
                                url:'delete',
                                data:{'id':data.id},
                                type:'post',
                                success:function (ret){
                                    layer.msg(ret.msg)
                                    obj.del();
                                    layer.close(index);
                                }
                            })
                        });
                    }else if(obj.event === 'scorelog'){

                        layer.open({
                            type: 2,
                            area: ['700px', '500px'],
                            content: 'scorelog?id='+data.id,
                            success:function (){
                            }
                        });

                    }else if(obj.event === 'shiming'){

                        layer.open({
                            type: 2,
                            area: ['700px', '500px'],
                            content: 'shiming?id='+data.id,
                            success:function (){
                                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                parent.layer.close(index); //再执行关闭
                            },
                            end:function (){
                                location.reload();
                            }
                        });

                    }
                    //参加的比赛
                    if(obj.event === 'game'){
                        layer.open({
                            type: 2,
                            area: ['1200px', '500px'],
                            content: 'game?id='+data.id,
                            success:function (){
                                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                parent.layer.close(index); //再执行关闭
                            },
                            end:function (){

                            }
                        });
                    }
                    //参加的比赛
                    if(obj.event === 'ticket'){
                        layer.open({
                            type: 2,
                            area: ['1000px', '700px'],
                            content: 'ticket?id='+data.id,
                            success:function (){
                                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                parent.layer.close(index); //再执行关闭
                            },
                            end:function (){

                            }
                        });
                    }


                    //参加报名
                    if(obj.event === 'baoming'){
                        layer.open({
                            type: 2,
                            title:'报名参赛',
                            area: ['1200px', '660px'],
                            content: 'baoming?id='+data.id,
                            success:function (){
                                // var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                // parent.layer.close(index); //再执行关闭
                            },
                            end:function (){
                                location.reload();


                            }
                        });
                    }
                    //kouchu

                    if(obj.event === 'kouchu'){

                        var ascore=data.score;

                        layer.prompt({
                            formType: 0,
                            title:'请输入扣除金额'
                        }, function(value, index){

                            var all=parseInt(ascore)-parseInt(value);

                            $.ajax({
                                url:'kouchu',
                                data:{'id':data.id,value:value},
                                type:'post',
                                success:function (ret){
                                    layer.msg(ret.msg)


                                    if (ret.code==1){
                                        obj.update({
                                            score: all
                                        });
                                    }
                                }
                            })
                        });
                    }


                    //修改积分
                     if(obj.event === 'congzi'){

                         var ascore=data.score;

                        layer.prompt({
                            formType: 0,
                            title:'请输入充值金额'
                        }, function(value, index){

                            var all=parseInt(ascore)+parseInt(value);

                            $.ajax({
                                url:'congzi',
                                data:{'id':data.id,value:value},
                                type:'post',
                                success:function (ret){



                                   layer.msg(ret.msg)

                                    if (ret.code==1){
                                        obj.update({
                                            score: all
                                        });

                                        layer.close(index);
                                        var logid=ret.data.logid;

                                        layer.open({
                                            type: 2,
                                            area: ['500px', '600px'],
                                            content: 'print?id='+logid,
                                            success:function (){

                                            },
                                            end:function (){
                                                //打印信息

                                                location.reload();
                                            }
                                        });

                                    }


                                }
                            })



                        });
                    }

                    //修改积分
                    if(obj.event === 'zengsong'){

                        var ascore=data.score;

                        layer.prompt({
                            formType: 0,
                            title:'请输入充值金额'
                        }, function(value, index){

                            var all=parseInt(ascore)+parseInt(value);

                            $.ajax({
                                url:'zengsong',
                                data:{'id':data.id,value:value},
                                type:'post',
                                success:function (ret){



                                    layer.msg(ret.msg)

                                    if (ret.code==1){
                                        obj.update({
                                            score: all
                                        });

                                        layer.close(index);
                                        var logid=ret.data.logid;
                                        console.log(logid);
                                        layer.open({
                                            type: 2,
                                            area: ['500px', '600px'],
                                            content: 'print?id='+logid,
                                            success:function (){
                                                // var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                                parent.layer.close(index); //再执行关闭
                                            },
                                            end:function (){
                                                location.reload();
                                            }
                                        });

                                    }


                                }
                            })



                        });
                    }




                });


            });
        </script>


    </table>

</div>
<script src="__STATIC__/js/admin.js"></script>
</body>
</html>